#
# @lc app=leetcode.cn id=13 lang=python3
#
# [13] 罗马数字转整数
#

# @lc code=start


class Solution:
    def romanToInt(self, s: str) -> int:
        symbol_value = {'M': 1000, 'D':500, 'C': 100, 'L': 50, 'X': 10, 'V': 5, 'I': 1}
        result = 0
        for i in range(len(s)-1):
            if symbol_value[s[i]] < symbol_value[s[i+1]]:
                result -= symbol_value[s[i]]
            else:
                result += symbol_value[s[i]]
        return result + symbol_value[s[-1]]
            
# @lc code=end

